package com.singzi.javaSenior.threads.basic;

import java.util.concurrent.*;

public class ThreadPool {
    public static void main(String[] args) {
//        ExecutorService executorService = Executors.newFixedThreadPool(10);
//        ThreadPoolExecutor service = (ThreadPoolExecutor) executorService;
//        service.setCorePoolSize(100);
//        System.out.println(executorService.getClass());
//        NumberThread numberThread = new NumberThread();
//        executorService.execute(new Number());
//        executorService.submit();//适和callable

        //手动构建线程池
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 4, 10, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(2),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        Thread t = new Thread(r);
                        t.setName("a");
                        return t;
                    }
                },new ThreadPoolExecutor.AbortPolicy());

        executor.execute(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println(i);
            }
        });

    }
}
